define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'factor/factor_review/index' + location.search,
                    add_url: 'factor/factor_review/add',
                    edit_url: 'factor/factor_review/edit',
                    del_url: 'factor/factor_review/del',
                    multi_url: 'factor/factor_review/multi',
                    import_url: 'factor/factor_review/import',
                    table: 'carbon_factor_review',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {field: 'id', title: __('Id'),searchable:false},
                        {field: 'factor_id', title: __('Factor_id'),searchList: Config.factorNameList, formatter: Table.api.formatter.normal},
                        {field: 'category_id', title: __('Category_id'),searchList: Config.categoryNameList,formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'),searchable:false},
                        {field: 'status', title: __('Status'),searchList: {'0' : '待审','1' : '已通过','2' : '驳回'}, formatter: Table.api.formatter.status},
                        {field: 'reason', title: __('Reason'),searchable:false, formatter: Table.api.formatter.content},
                        {field: 'checktime', title: __('Checktime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [{
                                name: 'del',
                                hidden:true,
                                disable:true,
                            }], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $('.faupload').hide();
            $('.fachoose').hide();
            Controller.api.bindevent();
            $('.btn-trash').hide();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
